#!/usr/bin/python

cmd = "xwininfo | grep 'Window id'"
xwinstr = popen(cmd).read()

xwd -id  | convert xwd:- cap.png
